#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from dragon.selector import Selector
from dragon.page import DraPage
from pages.calendar import Calendar

class StockSearchSe:
    calendarButton=Selector('div.date-time','日期按钮')
    searchInput=Selector('input.el-input__inner','搜索框')
    clearButton=Selector('div.search-reset','清空按钮')
    clearHistoryButton=Selector('div.clear-box.cp','清空历史按钮')
    stockBlock=Selector('div.result-item.cp','股票块')
    stock=Selector('div.result-name','股票(包含代码)')
    stockName=Selector('div.result-name>span:nth-child(1)','股票名称')
    stockCode=Selector('div.result-name>span:nth-child(3)','股票代码')
    highlightCode=Selector('div.result-name>span:nth-child(3)>span','高亮部分股票代码')
    labelName=Selector('div.label-text','股票标签名称')
    historyStock = Selector('div.history-item.cp', '历史股票(包含代码)')
    # historyStockName=Selector('div.history-item.cp>div.text','历史股票名字')
    # historyStockCode=Selector('div.history-item.cp>div.num','历史股票代码')
    searchAlert=Selector('p.el-message__content','搜索提示')

class StockSearchPage:
    def __init__(self, draPage: DraPage):
        self.draPage = draPage
        self.calendarButton = draPage.locator(StockSearchSe.calendarButton)
        self.searchInput = draPage.locator(StockSearchSe.searchInput)
        self.clearButton = draPage.locator(StockSearchSe.clearButton)
        self.clearHistoryButton = draPage.locator(StockSearchSe.clearHistoryButton)
        self.stockBlock = draPage.locator(StockSearchSe.stockBlock)
        self.stock = draPage.locator(StockSearchSe.stock)
        self.stockName = draPage.locator(StockSearchSe.stockName)
        self.stockCode = draPage.locator(StockSearchSe.stockCode)
        self.highlightCode = draPage.locator(StockSearchSe.highlightCode)
        self.labelName = draPage.locator(StockSearchSe.labelName)
        self.historyStock = draPage.locator(StockSearchSe.historyStock)
        self.searchAlert = draPage.locator(StockSearchSe.searchAlert)

    def pick_date_by_index(self, index: int):
        self.calendarButton.click()
        calendar = Calendar(self.draPage)
        calendar.pick_date_by_index(index)





